
var Profile = function() {

    var handleProfile = function () {
        $('.save-btn').on('click', function () {
            var _form = $('#ajax-form');
            //var _formData = $('#ajax-form').serializeObject();
            if(ajaxForm.loginName.value.trim() == ''){
                layer.msg('姓名不能为空！');
                ajaxForm.levelName.focus();
                return false;
            }
            if(!mdTool.validate(ajaxForm.phone.value, 'phone')){
                layer.msg('手机号格式不正确！');
                ajaxForm.phone.focus();
                return false;
            }
            if(ajaxForm.ori_password.value.trim() == ''){
                layer.msg('请输入原始密码！');
                ajaxForm.ori_password.focus();
                return false;
            }
            if(ajaxForm.password.value.trim()){
                if(ajaxForm.password.value.length < 6 || ajaxForm.password.value.length > 12){
                    layer.msg('密码长度在6-12位之间！');
                    ajaxForm.password.focus();
                    return false;
                }
                if(ajaxForm.password.value != ajaxForm.confirm_password.value){
                    layer.msg('两次密码不一致！');
                    ajaxForm.confirm_password.focus();
                    return false;
                }
            }


            var url = _form.attr('action');
            var data = _form.serialize();
            layer.load(2, {shade: [0.8,'#000000']}); // 打开loading
            $.ajax({
                url: url,
                type: 'POST',
                data: data,
                dataType : 'json',
                success: function (data) {
                    layer.closeAll('loading'); // 关闭loading
                    layer.msg(data.msg);
                    if(data.status == 1){
                        window.location.reload();
                    }
                }
            });
            return false;
        });
    };


    return {
        init: function() {
            handleProfile();
        }
    };

}();


$(function() {
    Profile.init();

});
